package com.china08.yxyapi.api;

import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.china08.yxyapi.security.JwtProfileUtil;
import com.china08.yxyapi.security.profile.YxyProfile;

public class YxyApiBaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(YxyApiBaseController.class);

    public YxyProfile getProfile(HttpServletRequest request, HttpServletResponse response) {
        return JwtProfileUtil.getProfile(request, response);
    }

    public String getDomainName(HttpServletRequest request) {
        String referer = request.getHeader("Referer");

        String domainName = "";
        try {
            URL url = new URL(referer);
            domainName = url.getHost();
        } catch (Exception e) {
            LOGGER.error("解析Referer异常(" + referer + "):" + e.getMessage());
        }
        return domainName;
    }
}
